import sys
import re

def fun(n):
    res = []
    lst = []
    for i in range(pow(10, n - 1), pow(10, n)):
        lst.append(i)
    for i in lst:
        numstr = str(i)
        sum = 0
        for k in range(0, len(numstr)):
            sum = sum + pow(int(numstr[k]), n)
        if sum == i:
            res.append(i)
    return res


def main():
    line = sys.stdin.readline()
    # for line in lines:
    line = re.sub('\n', ' ', line)
    m, n = line.split()
    s1 = int(m)
    s2 = int(n)
    res = fun(s1)
    res_l = len(res)
    if res:
        if s2 <= res_l:
            print(res[s2])
        else:
            print(res[-1])
    else:
        print(-1)

if __name__ == '__main__':
    main()
